var $ = require('../../lib/jquery');
var util = require('./common/util');
var nav = require('./common/nav');
var _header = require('./common/header');
var template = require('../tpl/template');
var minHeight = require('./common/minHeight');
minHeight.init();
var _nav = new nav();
var header = new _header();
$('.js_index').on('click', function(){
  location.href='./index.html'
})
var jzzn_ = {
  init: function(){
    this.firstFetch();
    this.doctorFetch();
    this.bindevent();
  },
  firstFetch: function(){
    var _this = this;
    util.fetch('api/emergency/queryLabelsList').then(function (res){
        _this.itemRender({data:res.data});
    }).fail(function(res){
      console.log(res)
    })
  },
  itemRender: function(data){
    var tpl = template('jzzn_wrap',data)
    console.log(tpl);
    $('.js_jzzn_wrap').html(tpl);
  },
  doctorRender: function (data) {
    var tpl = template('jzzn_doctor',data);
    $('.js_doctor_wrap').html(tpl);
  }, 
  doctorFetch: function (name) {
    var _this = this;
    util.fetch('api/emergency/list',{
      labels:name
    }).then(function(res){
      _this.doctorRender({data:res.data});
    })
  },
  bindevent: function (){
    var _this = this;
    $('.js_jzzn_wrap').on('click','span', function (){
      var id = $(this).data().id;
      var order = $(this).data().order;
      var name = $(this).data().name;

      $(this).siblings().removeClass('blue');
      $(this).addClass('blue');
      _this.doctorFetch(name, id, order);
    })
  }  
}
jzzn_.init();